package hit.reports;

import java.util.HashMap;
import java.util.Map;

/**
 * Represents a Row within a {@link BuilderTable}
 *
 */
public class TableRow {
	
	private Map<TableColumn, String> items;
	
	/**
	 * Default Constructor
	 */
	public TableRow()
	{
		items = new HashMap<TableColumn, String>();
	}
	
	/**
	 * Adds an item to the row.
	 * @param column The {@link TableColumn} the item should be added for.
	 * @param value The value of the new item.
	 * @throws IllegalArgumentException if the column is null or already in the row, 
	 * or the value is null.
	 */
	public void AddItem(TableColumn column, String value) throws IllegalArgumentException
	{
		if (column == null || items.get(column) != null || value == null)
		{
			throw new IllegalArgumentException();
		}
		
		items.put(column, value);
	}
	
	/**
	 * Edits an item in the row.
	 * @param column The {@link TableColumn} the item belongs to.
	 * @param newValue The newValue for the item.
	 * @throws IllegalArgumentException if the column is null or not in the 
	 * row or the value is null.
	 */
	public void EditItem(TableColumn column, String newValue) throws IllegalArgumentException
	{
		if (column == null || items.get(column) == null || newValue == null)
		{
			throw new IllegalArgumentException();
		}
		
		items.remove(column);
		items.put(column, newValue);
	}
	
	/**
	 * Removes an item from the row.
	 * @param column The {@link TableColumn} of the item that is to be removed.
	 * @throws IllegalArgumentException if column is null.
	 */
	public void RemoveItem(TableColumn column) throws IllegalArgumentException
	{
		if (column == null)
		{
			throw new IllegalArgumentException();
		}
		
		if (items.get(column) != null)
		{
			items.remove(column);
		}
	}
	
	/**
	 * Gets the value of an item from its {@link TableColumn}
	 * @param column The column the item belongs to.
	 * @return The value of the item. Null if the item is not in the system.
	 */
	public String GetItemValue(TableColumn column)
	{
		return items.get(column);
	}
}
